package demo.controller;

import demo.service.ElasticsearchService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

/**
 * @author qq872068101
 * @date 2020/4/17 21:23
 */
@RestController
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class TestController {
    private final ElasticsearchService elasticsearchService;

    private final String INDEX_NAME = "es-demo";

    @GetMapping("/createIndex")
    public void createIndex() throws IOException {
        elasticsearchService.createIndex(INDEX_NAME, 5,1);
    }

    @GetMapping("/existIndex")
    public boolean existIndex() throws IOException{
        return elasticsearchService.existIndex(INDEX_NAME);
    }

    @GetMapping("/addDocument1")
    public void addDocument1() throws IOException{
        elasticsearchService.addDocument1(INDEX_NAME);
    }

    @GetMapping("/addDocument2")
    public void addDocument2() throws IOException{
        elasticsearchService.addDocument2(INDEX_NAME);
    }

    @GetMapping("/updateDocument")
    public void updateDocument() throws IOException{
        elasticsearchService.updateDocument(INDEX_NAME);
    }
}
